package com.baseLearn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Collections;

/**
 * Created by foxx on 2018/6/25
 */
@Configuration
public class Swagger2Config {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select()// 选择那些路径和api会生成document
            .apis(RequestHandlerSelectors.basePackage("com.ssm.controller"))// 对所有controller下的api进行监控
            .paths(PathSelectors.any())// 对所有路径进行监控
            .build()
            .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        String str =
            "  <p>1. <b>code</b>: int类型，1表示正常返回，0表示异常返回！</p>" +
            "  <p>2. <b>data</b>: array类型（默认值:[]），data数组中属性定义各异，详见下方Responses下的example以及model中文说明！</p>" +
            "  <p>3. <b>errMsg</b>: string类型(默认值：null)，错误信息提示, 通常在code为0的情况下有值！</p>" +
            "  <p>4. <b>msg</b>: string类型(默认值：null)，正常信息提示, 通常在code为1的情况下有值！</p>";
        return new ApiInfo(
            "浙江海事局-OA体系",
            "<pre><code>注意：所有的api接口默认返回格式为：\n" +
                "{\n" +
                "  \"code\": 1,\n" +
                "  \"data\": [\n" +
                "  ],\n" +
                "  \"errMsg\": null,\n" +
                "  \"msg\": \"success\"\n" +
                "}</code></pre>" + str,
            "1.0.0",
            "关于api说明.",
            new Contact("admin", "192.192.192.192", "admin@allhigh.com.cn"),
            "License of API", "API license URL", Collections.emptyList());
    }

}
